package org.acghub.mtdb.core;

import org.acghub.mtdb.common.Lifecycle;
import org.acghub.mtdb.common.Pair;
import org.acghub.mtdb.common.exception.MtdbException;

/**
 * @author zhouhe
 */
public interface TableStorage<K, V> extends Lifecycle<Pair<Table<K, V>, StorageEngine>>{

    StorageEngine engine();

    Table<K, V> table();

    K minKey();

    K maxKey();

    K nextKey();

    long marshalN();

    long marshal0();

    long snapshot();

    long flush0();

    void cleanup();

    default long flush1() {
        long count = flush0();
        cleanup();
        return count;
    }

    void onChanged(TRecord<K, V> r);

    boolean exists(K key);

    V find(K key);

    /**
     * 验证key
     * @param key
     * @return
     */
    boolean verify(K key);

    void truncate();

    long count();
}
